package com.guodexian.service.impl;
import com.guodexian.dto.UserDto;
import com.guodexian.entity.User;
import com.guodexian.ex.PassException;
import com.guodexian.ex.TelException;
import com.guodexian.mapper.UserMapper;
import com.guodexian.service.UserService;
import org.mindrot.jbcrypt.BCrypt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
 * 类说明：<br>
 *
 * @author qfrx<br>
 * 2024/12/24 16:32<br>
 * @since 1.0 <br>
 */

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public User findUserByTelAndPass(String userTel, String userPass) throws PassException, TelException {
        User user = userMapper.selectByTel(userTel);
        if (user == null) {
            throw  new TelException();
        }
        if (!user.getUserPass().equals(userPass)) {
            throw new PassException();
        }
        return user;
    }

    @Override
    public void reg(User user) throws TelException {
        if (userMapper.selectByTel(user.getUserTel()) != null) {
            throw new TelException();
        }
        //加密存
        user.setUserPass(BCrypt.hashpw(user.getUserPass(), BCrypt.gensalt()));
        userMapper.insert(user);
    }
}
